// #include "util.hpp"
// #include "level.hpp"
// #include "message.hpp"
// #include "formatter.hpp"
// #include "sink.hpp"
// #include "extension.hpp"
// #include "logger.hpp"
// #include "buffer.hpp"

#include "../log_system/log_system.h"
#include "../extend/extension.hpp"

void test_log(const std::string& name)
{
    INFOLOG("%s","测试开始");
    // log_system::Logger::ptr logger = log_system::LoggerManager::getInstance()->getLogger(name);
    log_system::Logger::ptr logger = log_system::getLogger(name);
    logger->debugLog("%s","测试日志");
    logger->infoLog("%s","测试日志");
    logger->warnLog("%s","测试日志");
    logger->errorLog("%s","测试日志");
    logger->fatalLog("%s","测试日志");
    
    INFOLOG("%s","测试完毕");
}

int main()
{
//loggerManager.hpp
    std::unique_ptr<log_system::LoggerBuilder> builder(new log_system::GlobalLoggerBuilder());
    std::string name("async_logger");
    builder->buildLoggerName(name);
    builder->buildLoggerLevel(log_system::LogLevel::value::DEBUG);
    builder->buildFormatter("[%c][%f:%l][%p]%m%n");
    builder->buildLoggerType(log_system::LoggerType::LOGGER_ASYNC);
    builder->buildSink<log_system::StdoutSink>();
    builder->buildSink<log_system::FileSink>("./log/async.log");
    builder->buildSink<log_system::RollingBySizeSink>("./log/rollBySize-async-", 1024 * 1024);
    builder->build();

    test_log(name);



// //logger.hpp AsyncLogger
//     std::unique_ptr<log_system::LoggerBuilder> builder(new log_system::LocalLoggerBuilder());
//     builder->buildLoggerName("async_logger");
//     builder->buildLoggerLevel(log_system::LogLevel::value::WARN);
//     builder->buildFormatter("[%c]%m%n");
//     builder->buildLoggerType(log_system::LoggerType::LOGGER_ASYNC);

//     builder->buildSink<log_system::FileSink>("./log/async.log");
//     builder->buildSink<log_system::StdoutSink>();

//     log_system::Logger::ptr logger = builder->build();

//     logger->debugLog("%s%d","日志测试",1);
//     logger->infoLog("%s%d","日志测试",2);
//     logger->warnLog("%s%d","日志测试",3);
//     logger->errorLog("%s%d","日志测试",4);
//     logger->fatalLog("%s%d","日志测试",5);

//     int cnt = 0;
//     while(cnt < 1024 * 256)
//     {
//         logger->fatalLog("测试日志-%d", cnt++);
//     }

// //buffer.hpp
//     std::ifstream ifs("./log/testFileLog.log", std::ios::binary);
//     if(!ifs.is_open())
//     {
//         std::cout << "open failed!\n";
//         return -1;
//     } 
//     ifs.seekg(0, std::ios::end);
//     size_t fsize = ifs.tellg();
//     ifs.seekg(0, std::ios::beg);

//     std::string s;
//     s.resize(fsize);
//     ifs.read(&s[0], fsize);
//     if(!ifs.good())
//     {
//         std::cout << "read failed!\n";
//         return -1;
//     }
//     ifs.close();

//     log_system::Buffer buffer;
//     for(size_t i = 0; i < s.size(); ++i)
//     {
//         buffer.push(&s[i], 1);
//     }

//     std::ofstream ofs("./log/temp.log", std::ios::binary);
//     int size = buffer.readableSize();
//     while(size--)
//     {
//         ofs.write(buffer.data(), 1);
//         buffer.moveReader(1);
//     }
//     ofs.close();




// //logger.hpp LoggerBuilder
//     std::unique_ptr<log_system::LoggerBuilder> pBuilder(new log_system::LocalLoggerBuilder());
//     pBuilder->buildLoggerName("sync_logger");
//     pBuilder->buildFormatter("{%d{%Y/%m/%d-%H:%M:%S}}[%t][%f:%l][%p]%T%m%n");
//     pBuilder->buildLoggerLevel(log_system::LogLevel::value::INFO);
//     pBuilder->buildLoggerType(log_system::LoggerType::LOGGER_SYNC);
//     log_system::Logger::ptr logger = pBuilder->build();
//     logger->debugLog("%s%d","日志测试",1);
//     logger->infoLog("%s%d","日志测试",2);
//     logger->warnLog("%s%d","日志测试",3);
//     logger->errorLog("%s%d","日志测试",4);
//     logger->fatalLog("%s%d","日志测试",5);
//     // logger->debugLog(__FILE__,__LINE__,"%s%d","日志测试",1);
//     // logger->infoLog(__FILE__,__LINE__,"%s%d","日志测试",2);
//     // logger->warnLog(__FILE__,__LINE__,"%s%d","日志测试",3);
//     // logger->errorLog(__FILE__,__LINE__,"%s%d","日志测试",4);
//     // logger->fatalLog(__FILE__,__LINE__,"%s%d","日志测试",5);



// //logger.hpp
//     std::string loggerName = "syn_logger";
//     log_system::LogLevel::value limit = log_system::LogLevel::value::WARN;
//     log_system::Formatter::ptr pFormatter(new log_system::Formatter("[%d{%H:%M:%S}][%c][%f:%l][%p]%T%m%n"));
//     std::vector<log_system::LogSink::ptr> sinks;

//     log_system::LogSink::ptr pStdoutSink = log_system::SinkFactory::create<log_system::StdoutSink>();
//     log_system::LogSink::ptr pFileSink = log_system::SinkFactory::create<log_system::FileSink>("./log/testFileLog.log");
//     log_system::LogSink::ptr pRollingBySizeSink = log_system::SinkFactory::create<log_system::RollingBySizeSink>("./log/testRollingLog-", 1024 * 1024);

//     sinks.push_back(pStdoutSink);
//     sinks.push_back(pFileSink);
//     sinks.push_back(pRollingBySizeSink);


//     log_system::Logger::ptr pLogger(new log_system::SyncLogger(loggerName, limit, pFormatter, sinks));
//     pLogger->debugLog("测试日志");
//     pLogger->infoLog("测试日志");
//     pLogger->warnLog("测试日志");
//     pLogger->errorLog("测试日志");
//     pLogger->fatalLog("测试日志%s-%d","fatal",1);

//     int cnt = 0;
//     while(cnt < 1024 * 512)
//     {
//         pLogger->fatalLog("测试日志-%d", cnt++);
//     }

//     // pLogger->debugLog(__FILE__, __LINE__, "测试日志");
//     // pLogger->infoLog(__FILE__, __LINE__, "测试日志");
//     // pLogger->warnLog(__FILE__, __LINE__, "测试日志");
//     // pLogger->errorLog(__FILE__, __LINE__, "测试日志");
//     // pLogger->fatalLog(__FILE__, __LINE__, "测试日志%s-%d","fatal",1);

//     // int cnt = 0;
//     // while(cnt < 1 * 128)
//     // {
//     //     pLogger->fatalLog(__FILE__, __LINE__, "测试日志-%d", cnt++);
//     // }




// //sink.hpp extension.hpp

//     log_system::Formatter fmt;

//     log_system::SinkFactory factory;
//     log_system::LogSink::ptr pRollingByTimeSink = factory.create<extensionLS::RollingByTimeSink>("./log/extensionLog/rollingLog-", extensionLS::TimeInterval::SECOND_INTERVAL);

//     time_t start = log_system::util::Date::now();

//     while(log_system::util::Date::now() < start + 5)
//     {
//         log_system::LogMsg msg(log_system::LogLevel::value::INFO, __FILE__, __LINE__, "root", "日志格式化功能测试...");
//         std::string str = fmt.format(msg);
//         pRollingByTimeSink->log(str.c_str(), str.size());
//     }



// //sink.hpp

//     log_system::LogMsg msg(log_system::LogLevel::value::INFO, __FILE__, __LINE__, "root", "日志格式化功能测试...");
//     log_system::Formatter fmt;
//     std::string str = fmt.format(msg);

//     log_system::SinkFactory factory;
//     log_system::LogSink::ptr stdoutSinkPtr = factory.create<log_system::StdoutSink>();
//     log_system::LogSink::ptr fileSinkPtr = factory.create<log_system::FileSink>("./log/test.log");
//     log_system::LogSink::ptr rollingSinkPtr = factory.create<log_system::RollingBySizeSink>("./log/rollingTest-", 1024 * 1024);

//     stdoutSinkPtr->log(str.c_str(), str.size());
//     fileSinkPtr->log(str.c_str(), str.size());

//     size_t cnt = 0;
//     size_t curSize = 0;
//     std::string tmp;
//     while(curSize <= 1024 * 1024 * 10)
//     {
//         tmp = std::to_string(cnt++) + str;
//         rollingSinkPtr->log(tmp.c_str(), tmp.size());
//         curSize += tmp.size();
//     }
//     std::cout << cnt << std::endl;
    


// //formatter.hpp

//     log_system::LogMsg msg(log_system::LogLevel::value::INFO, __FILE__, __LINE__, "root", "日志格式化功能测试...");
//     // log_system::Formatter formatter;
//     // log_system::Formatter formatter("%tabc%%abc[%d{%H:%M:%S}] %m%n");
//     // log_system::Formatter formatter("%%%%%t abc%%abc[%d{%H:%M:%S}] %m%n");
//     log_system::Formatter formatter("%%%%%t%%abc%%a%u{a}bc[%d{%H:%M:%S}] %m%n%%%");
//     // log_system::Formatter formatter("%%%%%t%%abc%%abc[%d{%H:%M:%S}] %m%n123123");
//     // log_system::Formatter formatter("%%%%%t%%abc%%a%bc[%d{%H:%M:%S}] %m%n123123");
//     // log_system::Formatter formatter("123456");
//     // log_system::Formatter formatter("123456%%");
//     std::string str = formatter.format(msg);
//     std::cout << str << std::endl;



// //message.hpp
//     log_system::LogMsg msg(log_system::LogLevel::value::WARN,__FILE__,__LINE__,"root","内容");



// //level.hpp
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::UNKNOW) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::DEBUG) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::INFO) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::WARN) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::ERROR) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::FATAL) << std::endl;
//     std::cout << log_system::LogLevel::toString(log_system::LogLevel::value::OFF) << std::endl;
//     std::cout << log_system::LogLevel::toString((log_system::LogLevel::value)123123) << std::endl;


// //util.hpp
//     std::cout << log_system::util::Date::now() << std::endl;
//     std::cout << log_system::util::File::exist("/home/yjcg/log_system/practice/args") << std::endl;
//     std::cout << log_system::util::File::parentPath("/home/yjcg/log_system/practice/args") << std::endl;
//     std::cout << log_system::util::File::parentPath("/home/yjcg/log_system/practice") << std::endl;
//     log_system::util::File::createDirectory("./testmkdir/");
//     log_system::util::File::createDirectory("./testmkdir2/test2/asd");
//     log_system::util::File::createDirectory("as");

    return 0;
}